package com.kaifamiao.arrays;

import java.util.Arrays;

// 判断两个不同的数组实例是否"相等":
// 1、首先数组长度相等(元素个数相同)
// 2、其次相应位置的元素都相等(相同下标处的元素相等)
public class Equal {
    public static void main(String[] args) {

        int[] first = { 10, 0, 4, 88 };
        System.out.println( first );

        int[] second = { 10, 0, 4, 88 };
        System.out.println( second );

        System.out.println( first == second ); // false

        if( first == second ) {
            System.out.println( "相等" );
        } else if( first.length == second.length ) {
            boolean equal = true;
            for (int i = 0; i < first.length; i++) {
                if( first[i] != second[i] ) {
                    equal = false;
                    break;
                }
            }
            System.out.println( equal ? "相等" : "不相等" );
        } else {
            System.out.println( "两个数组不相等" );
        }

        System.out.println( "- ".repeat( 10 ) );

        boolean result = Arrays.equals( first, second );
        System.out.println( result );
    }
}
